package com.fan.controller.portal;


import com.fan.common.Const;
import com.fan.common.ServerResponse;
import com.fan.pojo.User;
import com.fan.service.ICartService;
import com.fan.vo.CartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/cart/")
public class CartController {

    @Autowired
    private ICartService iCartService;


    @RequestMapping("add.do")
    @ResponseBody
    public ServerResponse<CartVo> add(HttpSession session, Integer userId, Integer count, Integer productId){
        return iCartService.add(userId,productId,count);
    }
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<CartVo> list(HttpSession session, Integer userId){
        return iCartService.list(userId);
    }

    @RequestMapping("apdate.do")
    @ResponseBody
    public ServerResponse<CartVo> apdate(HttpSession session, Integer userId, Integer count, Integer productId){
        return iCartService.update(userId,productId,count);
    }

    @RequestMapping("delete.do")
    @ResponseBody
    public ServerResponse<CartVo> delete(HttpSession session, Integer userId,String productIds){
        return iCartService.deleteProduct(userId,productIds);
    }


    @RequestMapping("select_all.do")
    @ResponseBody
    public ServerResponse<CartVo> selectAll(HttpSession session, Integer userId,String productIds){
        return iCartService.selectOrUnSelectAll(userId, Const.Cart.CHECKED);
    }

    @RequestMapping("un_select_all.do")
    @ResponseBody
    public ServerResponse<CartVo> unSelectAll(HttpSession session, Integer userId,String productIds){
        return iCartService.selectOrUnSelectAll(userId, Const.Cart.UN_CHECK);
    }
}
